<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px">
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.instanceName"
          clearable
          placeholder="请输入名称"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发起时间" prop="deployTime">
        <el-date-picker v-model="queryParams.beginDate" clearable
                        placeholder="开始时间"
                        size="small"
                        type="date"
                        value-format="yyyy-MM-dd"
        />
        至
        <el-date-picker v-model="queryParams.endDate" clearable
                        placeholder="结束时间"
                        size="small"
                        type="date"
                        value-format="yyyy-MM-dd"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">
          搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="finishedList" border @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="55" />
      <el-table-column :show-overflow-tooltip="true" align="center" label="任务编号" prop="taskId" />
      <el-table-column :show-overflow-tooltip="true" align="center" label="流程名称" prop="procDefName" />
      <el-table-column align="center" label="任务节点" prop="taskName" />
      <el-table-column align="center" label="流程发起人">
        <template slot-scope="scope">
          <label>{{ scope.row.startUserName }}
            <el-tag size="mini" type="info">{{ scope.row.startDeptName }}</el-tag>
          </label>
        </template>
      </el-table-column>
      <el-table-column align="center" label="接收时间" prop="createTime" width="180" />
      <el-table-column align="center" label="审批时间" prop="finishTime" width="180" />
      <el-table-column align="center" label="评论" prop="comment" width="180" />
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button
            icon="el-icon-tickets"
            size="mini"
            type="text"
            @click="handleFlowRecord(scope.row)"
          >
            流转记录
          </el-button>
          <!--          <el-button-->
          <!--            icon="el-icon-tickets"-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            @click="handleRevoke(scope.row)"-->
          <!--          >-->
          <!--            撤回-->
          <!--          </el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :limit.sync="queryParams.size"
      :page.sync="queryParams.current"
      :total="total"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listFinishedTask} from "@/api/workflow/finished"

export default {
  name: "FinishedProcess",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 已办任务列表数据
      finishedList: [],
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        name: null,
        beginDate: null,
        endDate: null
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询流程定义列表 */
    getList() {
      this.loading = true
      listFinishedTask(this.queryParams).then((response) => {
        this.finishedList = response.data.records
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleFlowRecord(row) {
      this.$router.push({
        path: '/workflow/task/record/handle',
        query: {
          procInsId: row.procInsId,
          taskId: row.taskId,
          deployId: row.deployId,
          operated: false
        }
      })
    }
  }
}
</script>

